(function ($) {
    //获取项目根路径
    function login() {
        var self = this;
        self.dom = $(document);
        self.login();
    }

    login.prototype = {
        login: function () {
            var self = this;
            self.dom.on("click", "#login", function () {
                var userName = $("#userName").val();
                var password = $("#password").val();
                if (userName == "" || password == "") {
                    alert("用户或密码不能为空!");
                } else {
                    $.ajax({
                        url: 'userInfo/login',
                        data: JSON.stringify({"username": userName, "password": password, "onDuty": true}),
                        type: 'post',
                        dataType: 'json',
                        headers: {
                            Accept: "application/json", "Content-Type": "application/json"
                        }, success: function (data) {
                            if (data.code == "1000") {
                                window.location = "/index";
                            } else if (data.code == "10002") {
                                alert("用户名或密码错误");
                            } else {
                                alert("系统出错请联系管理员！！");
                            }
                        }, error: function (e) {
                            console.log("出错了" + e);
                        }
                    });
                }
            });
            return self;
        }
    }
    new login();
})(jQuery);
